﻿package plugin.specialActivity.game
{
    import cmd.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import plugin.specialActivity.*;
    import pluginfw.nio.*;
    import uiresource.specialActivity.*;
    import view.mornExtends.*;
    import view.uilt.*;

    public class JiZhiGame extends JizhiUI implements IPage
    {
        private var _pageMsg:Object;
        private var goalMsgArr:Array;

        public function JiZhiGame(param1:Object)
        {
            this._pageMsg = param1;
            this.initEvent();
            return;
        }// end function

        private function initEvent() : void
        {
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_1:Object = null;
            var _loc_2:ItemSplit = null;
            var _loc_3:Array = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            if (this.goalMsgArr == null)
            {
                this.goalMsgArr = [];
                _loc_1 = ConfigDictionary.data.activitygoal;
                _loc_2 = new ItemSplit();
                _loc_3 = _loc_1[this._pageMsg.id];
                _loc_4 = ConfigDictionary.data.item;
                for each (_loc_5 in _loc_3)
                {
                    
                    _loc_5.itemArr = _loc_2.doSplits(_loc_5.goalname, "/", "&", "#")[0];
                    _loc_5.targetArr = [_loc_4[_loc_5.reward]];
                    this.goalMsgArr.push(_loc_5);
                }
            }
            list.array = this.goalMsgArr;
            list.renderHandler = new Handler(this.goalRender);
            return;
        }// end function

        private function goalRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Button = null;
            var _loc_5:List = null;
            var _loc_6:List = null;
            if (param2 < list.length)
            {
                _loc_3 = param1.dataSource;
                _loc_4 = param1.getChildByName("btn_duihuan") as Button;
                _loc_4.clickHandler = new Handler(this.dolq, [_loc_3.id, _loc_3.goal, _loc_3.type, true]);
                _loc_5 = param1.getChildByName("list_item") as List;
                _loc_5.array = _loc_3.itemArr;
                _loc_5.renderHandler = new Handler(this.itemRender, [_loc_5, _loc_4, [_loc_3.id, _loc_3.goal, _loc_3.type, false]]);
                _loc_6 = param1.getChildByName("list_target") as List;
                _loc_6.array = _loc_3.targetArr;
                _loc_6.renderHandler = new Handler(this.targetRender, [_loc_6]);
            }
            return;
        }// end function

        private function targetRender(param1:List, param2:Component, param3:int) : void
        {
            if (param3 < param1.length)
            {
                (param2 as FlashItem).data = param2.dataSource;
            }
            return;
        }// end function

        private function dolq(param1:int, param2:int, param3:int, param4:Boolean) : void
        {
            var _loc_5:Output = null;
            if (param4)
            {
                _loc_5 = new Output();
                _loc_5.writeVarInt(param1, false);
                _loc_5.writeVarInt(param2, false);
                _loc_5.writeVarInt(param3, false);
                PluginManager.instance.sendToBufferServer("kaifujingji", CMDKaifuJJ.SendgoalLJMassage, _loc_5);
            }
            else
            {
                WarningManager.show(168);
            }
            return;
        }// end function

        private function itemRender(param1:List, param2:Button, param3:Array, param4:Component, param5:int) : void
        {
            var _loc_6:Object = null;
            var _loc_7:Label = null;
            var _loc_8:int = 0;
            if (param5 < param1.length)
            {
                _loc_6 = param4.dataSource;
                (param4 as FlashItem).data = _loc_6;
                _loc_7 = param4.getChildByName("hascount") as Label;
                _loc_8 = ItemUilt.getAllCount(_loc_6.itemid);
                if (_loc_8 < _loc_6.count)
                {
                    param4.disabled = true;
                    param2.clickHandler = new Handler(this.dolq, param3);
                }
                else
                {
                    param4.disabled = false;
                }
                _loc_7.text = _loc_8 + "";
            }
            return;
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            switch(param1)
            {
                case ActivityPublic.UPDATETIME:
                {
                    txt_countdown.text = String(param2);
                    break;
                }
                case ActivityPublic.UPDATEBAG:
                {
                    list.refresh();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
